package com.levi.completableFuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @author shentong
 * @since 2022/1/16 3:49 PM
 * 创建没有返回值的异步任务
 */
public class RunAsyncDemo {

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        //创建CompletableFuture,使用2个参数的runAsync()方法即可,因为commonPool里main的线程是守护线程
        CompletableFuture.runAsync(()->{
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("线程任务执行～");
        },executorService);
        System.out.println("Main线程执行");
        executorService.shutdown();
    }
}
